package com.buba.springcloud.servlet;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
public class MyListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
//        创建的时候添加
        HttpSession session = httpSessionEvent.getSession();
//        为了效果更明显
        session.setMaxInactiveInterval(1);
        String id = session.getId();
        User.add(id);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        //        销毁的时候移出
        HttpSession session = httpSessionEvent.getSession();
        String id = session.getId();
        User.remove(id);
    }
}
